home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Apple Shared Library Manager / ASLM Examples / TestTools / Sources / SIVTableTest.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  5.8 KB  |  243 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SIVTableTest.cp
  3.  
  4.     Contains:    Program to use the test shared classes
  5.  
  6.     Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #include <GlobalNew.h>
  11. #ifndef __STDIO__
  12. #include <stdio.h>
  13. #endif
  14. #ifndef __CTYPE__
  15. #include <ctype.h>
  16. #endif
  17. #ifndef __LIBRARYMANAGERUTILITIES__
  18. #include <LibraryManagerUtilities.h>
  19. #endif
  20.  
  21. #include "SITestClasses.h"
  22.  
  23. /*******************************************************************************
  24. ** Class TSITest3a
  25. ********************************************************************************/
  26.  
  27. static short    gState    = 0;
  28.  
  29. class TSITest3a : public TSITest3
  30. {
  31.     public:
  32.                         _CDECL TSITest3a();
  33.         virtual            ~_CDECL TSITest3a();
  34.         
  35.         virtual int        _CDECL VTest1(int, int);
  36.         virtual int        _CDECL VTest2(int, int);
  37.                 
  38.     private:
  39.         int        fField2;
  40. };
  41.  
  42. /*******************************************************************************
  43. ** Class TSITest3a
  44. ********************************************************************************/
  45.  
  46. //
  47. //    This is needed because we inherit from TSITest3 (which declares DummyVirtualFunction)
  48. //    but we don't export our subclass. Since we don't export it, our vtable will make
  49. //    a reference to the inherited DummyVirtualFunction method so we need to
  50. //     define it here or our link will fail.
  51. //
  52. ASLM_SCDECLARATION(TSITest3);
  53.  
  54. TSITest3a::TSITest3a()
  55. {
  56.     fField2 = gState++;
  57. }
  58.  
  59. TSITest3a::~TSITest3a()
  60. {
  61.     switch (fField2)
  62.     {
  63.         case 0:
  64.             if (gState++ != fField2 + 3)
  65.                 DoDebugBreak("TSITest3a::~TSITest3a - gState not right");
  66.             break;
  67.             
  68.         default:
  69.             gState += 1;
  70.             DoDebugBreak("TSITest3a::~TSITest3a - fField2 not right");
  71.             break;
  72.     }
  73. }
  74.  
  75. int TSITest3a::VTest1(int a, int b)
  76. {
  77.     switch (fField2)
  78.     {
  79.         case 0:
  80.             if (a != 37 || b != 38)
  81.                 DoDebugBreak("TSiTest3a::VTest1 - arguments incorrect");
  82.             if (gState++ != fField2 + 1)
  83.                 DoDebugBreak("TSiTest3a::VTest1 - gState not right");
  84.             break;
  85.             
  86.         default:
  87.             gState += 1;
  88.             DoDebugBreak("TSITest3a::VTest1 - fField2 not right");
  89.     }
  90.     return TSITest3::VTest1(a, b);
  91. }
  92.  
  93. int TSITest3a::VTest2(int a, int b)
  94. {
  95.     switch (fField2)
  96.     {
  97.         case 0:
  98.             if (a != 39 || b != 40)
  99.                 DoDebugBreak("TSiTest3a::VTest2 - arguments incorrect");
  100.             if (gState++ != fField2 + 2)
  101.                 DoDebugBreak("TSiTest3a::VTest2 - gState not right");
  102.             break;
  103.             
  104.         default:
  105.             gState += 1;
  106.             DoDebugBreak("TSITest3a::VTest2 - fField not right");
  107.             break;
  108.     }
  109.     return TSITest3::VTest2(a, b);
  110. }
  111.  
  112. /*******************************************************************************
  113. ** Main
  114. ********************************************************************************/
  115.  
  116. int main(int argc, char** argv)
  117. {
  118.     int        a, b, c, d, e, f;
  119.     Boolean    doBreak = false;
  120.     short    index;
  121.     
  122.     for (index = 1; index < argc; index++)
  123.     {
  124.         if (argv[index][0] == '-')
  125.         { 
  126.             switch (tolower(argv[index][1]))
  127.             {
  128.                 case 'x':
  129.                     doBreak = true;
  130.                     break;
  131.                     
  132.                 default:
  133.                     fprintf(stderr, "### ERROR: Unknown option - '%s'\n", argv[index]);
  134.                     return 1;
  135.             }
  136.         }
  137.         else
  138.         {
  139.             fprintf(stderr, "### ERROR: Unknown option - '%s'\n", argv[index]);
  140.             return 1;
  141.         }
  142.     }
  143.     
  144.     if (doBreak)
  145.         DoDebugBreak("About to call InitLibraryManager");
  146.  
  147.     InitLibraryManager();
  148.     TRY
  149.         InitTestLibrary();
  150.         {
  151.             TNVTest1* test = new TNVTest1;    // state 0
  152.             a = test->NVTest1(1, 2);        // state 1
  153.             b = test->NVTest2(3, 4);        // state 2
  154.             delete test;                    // state 3
  155.         }
  156.         {
  157.             TNVTest2* test = new TNVTest2;    // state 4 & 5
  158.             a = test->NVTest1(5, 6);        // state 6
  159.             b = test->NVTest2(7, 8);        // state 7
  160.             c = test->NVTest3(9, 10);        // state 8
  161.             d = test->NVTest4(11, 12);        // state 9
  162.             delete test;                    // state 10 & 11
  163.         }
  164.         {
  165.             TSITest1* test = new TSITest1;    // state 12
  166.             a = test->VTest1(13, 14);        // state 13
  167.             b = test->VTest2(15, 16);        // state 14
  168.             c = test->NVTest1(17, 18);        // state 15
  169.             d = test->NVTest2(19, 20);        // state 16
  170.             delete test;                    // state 17
  171.         }
  172.         {
  173.             TSITest2* test = new TSITest2;    // state 18
  174.             a = test->VTest1(21, 22);        // state 19
  175.             b = test->VTest2(23, 24);        // state 20
  176.             c = test->NVTest1(25, 26);        // state 21
  177.             d = test->NVTest2(27, 28);        // state 22
  178.             delete test;                    // state 23
  179.         }
  180.         {
  181.             TSITest3* test = new TSITest3;    // state 24
  182.             a = test->VTest1(29, 30);        // state 25
  183.             b = test->VTest2(31, 32);        // state 26
  184.             c = test->NVTest1(33, 34);        // state 27
  185.             d = test->NVTest2(35, 36);        // state 28
  186.             delete test;                    // state 29
  187.         }
  188.         {
  189.             TSITest3a* test = new TSITest3a;// state 30
  190.             a = test->VTest1(37, 38);        // state 31
  191.             if (gState != 2)
  192.                 DoDebugBreak("Call to TSITest3a::VTest1 did not go locally");
  193.             if (GetStateValue() != 32)
  194.                 DoDebugBreak("Call to TSITest3a::VTest1 did not go to inherited");
  195.             b = test->VTest2(39, 40);        // state 32
  196.             if (gState != 3)
  197.                 DoDebugBreak("Call to TSITest3a::VTest2 did not go locally");
  198.             if (GetStateValue() != 33)
  199.                 DoDebugBreak("Call to TSITest3a::VTest2 did not go to inherited");
  200.             c = test->NVTest1(41, 42);        // state 33
  201.             d = test->NVTest2(43, 44);        // state 34
  202.             delete test;                    // state 35
  203.             if (gState != 4)
  204.                 DoDebugBreak("Call to TSITest3a::~TSITest3a did not go locally");
  205.             if (GetStateValue() != 36)
  206.                 DoDebugBreak("Call to TSITest3a::~TSITest3a did not go to inherited");
  207.         }
  208.         {
  209.             TSITest4* test = new TSITest4;
  210.             a = test->VTest1(4, 2);
  211.             b = test->VTest2(4, 2);
  212.             c = test->VTest3(4, 2);
  213.             d = test->VTest4(4, 2);
  214.             e = test->NVTest1(4, 2);
  215.             f = test->NVTest2(4, 2);
  216.             delete test;
  217.         }
  218.         {
  219.             TSITest5* test = new TSITest5;
  220.             a = test->VTest1(4, 2);
  221.             b = test->VTest2(4, 2);
  222.             c = test->VTest3(4, 2);
  223.             d = test->VTest4(4, 2);
  224.             e = test->NVTest1(4, 2);
  225.             f = test->NVTest2(4, 2);
  226.             delete test;
  227.         }
  228.         {
  229.             TSITest5 test;
  230.             a = test.VTest1(4, 2);
  231.             b = test.VTest2(4, 2);
  232.             c = test.VTest3(4, 2);
  233.             d = test.VTest4(4, 2);
  234.             e = test.NVTest1(4, 2);
  235.             f = test.NVTest2(4, 2);
  236.         }
  237.     CATCH_ALL
  238.         fprintf(stderr, "TestLibrary is not installed!\n");
  239.     ENDTRY
  240.     CleanupLibraryManager();
  241.     return 0;
  242. }
  243.